﻿using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace HobSoft.SoccerBet2014.Common.Wpf.Converter
{
    public class BrushAnimationConverter : IMultiValueConverter, IValueConverter
    {
        public double Duration { get; set; }
        public Color FromColor { get; set; }
        public Color ToColor { get; set; }
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Duration dur = new Duration(TimeSpan.FromSeconds(Duration / 1000));
            var ca = new ColorAnimation(FromColor, ToColor, dur);
            var da = new DoubleAnimation(100d, 0d, dur);
            Storyboard sb = new Storyboard();
            SolidColorBrush brush = new SolidColorBrush();
            brush.BeginAnimation(SolidColorBrush.ColorProperty, ca);
            brush.BeginAnimation(SolidColorBrush.OpacityProperty, da);
            return brush;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Duration dur = new Duration(TimeSpan.FromSeconds(Duration / 1000));
            var ca = new ColorAnimation(FromColor, ToColor, dur);
            var da = new DoubleAnimation(100d, 0d, dur);
            Storyboard sb = new Storyboard();
            SolidColorBrush brush = new SolidColorBrush();
            brush.BeginAnimation(SolidColorBrush.ColorProperty, ca);
            brush.BeginAnimation(SolidColorBrush.OpacityProperty, da);
            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
